//
//  AddTextFiledView.m
//  IceBoxStrorage
//
//  Created by xieyanhong on 2023/8/21.
//

#import "AddTextFiledView.h"

@implementation AddTextFiledView

-(instancetype)init{
    if (self = [super initWithFrame:CGRectZero]) {
        [self initSubView];
    }
    
    return self;
}

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self initSubView];
    }
    return self;
}

-(void)setNameStr:(NSString *)nameStr{
    _nameStr = nameStr;
    self.nameLabel.text = nameStr;
    self.textFild.placeholder = [NSString stringWithFormat:@"input %@",nameStr];
}

- (void)initSubView{
    
    self.backgroundColor = [UIColor whiteColor];
    UIView *baseView = [[UIView alloc]init];
    [self addSubview:baseView];
    [baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self).insets(UIEdgeInsetsMake(8, 8, 8, 8));
    }];
    baseView.backgroundColor = rgba(245, 245, 245, 1);
    baseView.layer.cornerRadius = 4;
    baseView.layer.masksToBounds = YES;
    
    
    UILabel *titleLabel = [[UILabel alloc]init];
    [baseView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(baseView.mas_centerY);
        make.left.equalTo(@8);
    }];
    titleLabel.textAlignment = NSTextAlignmentLeft;
    titleLabel.font = [UIFont boldSystemFontOfSize:14];
    titleLabel.textColor = UIColor.blackColor;
    [titleLabel sizeToFit];
    self.nameLabel = titleLabel;
    
    UITextField *textFiled = [[UITextField alloc]init];
    [baseView addSubview:textFiled];
    [textFiled mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLabel.mas_right).offset(16);
        make.right.equalTo(@-16);
        make.top.equalTo(@4);
        make.bottom.equalTo(@-4);
    }];
    textFiled.borderStyle = UITextBorderStyleRoundedRect;
    textFiled.textColor = [UIColor blackColor];
    textFiled.font = [UIFont systemFontOfSize:14];
    self.textFild = textFiled;
    
    UIButton *deviceButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
    self.moreBtn = deviceButton;
    textFiled.rightView = deviceButton;
    textFiled.rightViewMode = UITextFieldViewModeAlways;
    
    
}

@end
